package com.jusda.aop;

import com.jusda.util.ThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author:y022 24/04/2022 15:01
 * @description:
 */
@Aspect
@Component
@Slf4j
public class TimeCostLog {

    @Pointcut("execution(* com.jusda.api.controller.*.*(..))")
    private void pointCut() {

    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) {
        ThreadLocalUtil.setValue();
        try {
            joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        log.debug("{} 接口执行耗时：{} ms", joinPoint.getSignature().getName(), System.currentTimeMillis() - ThreadLocalUtil.getValue());
        return null;
    }
}
